#include "modbuswig.h"
#include "ui_modbuswig.h"

ModbusWig::ModbusWig(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ModbusWig)
{
    ui->setupUi(this);
    ui->pushButton_humidity->setIcon(QIcon(":/ekefangshidu.png"));
    ui->pushButton_humidity->setIconSize(QSize(100,100));
    ui->pushButton_ill->setIcon(QIcon(":/eqitijiance.png"));
    ui->pushButton_ill->setIconSize(QSize(100,100));
    ui->pushButton_switch->setIcon(QIcon(":/new/prefix1/newair_cond.png"));
    ui->pushButton_switch->setIconSize(QSize(100,100));
    ui->pushButton_alarm->setIcon(QIcon(":/ekefangbaojing.png"));
    ui->pushButton_alarm->setIconSize(QSize(100,100));
    ui->pushButton_temp->setIcon(QIcon(":/ewendukz.png"));
    ui->pushButton_temp->setIconSize(QSize(100,100));
    ui->pushButton_light->setIcon(QIcon(":/new/prefix1/newlight.png"));
    ui->pushButton_light->setIconSize(QSize(100,100));
    connect(ui->pushButton_switch,SIGNAL(clicked()),this,SLOT(gust_swithkz()));
    connect(ui->pushButton_light,SIGNAL(clicked()),this,SLOT(gust_lightkz()));
    connect(ui->pushButton_alarm,SIGNAL(clicked()),this,SLOT(gust_alarmkz()));
    connect(ui->pushButton_temp,SIGNAL(clicked()),this,SLOT(gust_temkz()));
    connect(ui->pushButton_sx,SIGNAL(clicked()),this,SLOT(modsx()));

}

ModbusWig::~ModbusWig()
{
    delete ui;
}

void ModbusWig::mbappilldata(QString str)
{
    ui->label->setText(str);
}

void ModbusWig::mbapphumiditydata(QString str)
{
    ui->label_2->setText(str);
}

void ModbusWig::gust_swithkz()
{
    if(ui->label_3->text()=="off")
    {
        int kfkt=0;
        ui->label_3->setText("on");
        emit mobswith(kfkt);
    }
    else if(ui->label_3->text()=="on")
    {
        int kfkt=1;
        ui->label_3->setText("off");
        emit mobswith(kfkt);
    }
}

void ModbusWig::gust_lightkz()
{
    if(ui->label_5->text()=="off")
    {
        int kfd=0;
        ui->label_5->setText("on");
        emit moblight(kfd);
    }
    else if(ui->label_5->text()=="on")
    {
        int kfd=1;
        ui->label_5->setText("off");
        emit moblight(kfd);
    }
}

void ModbusWig::gust_alarmkz()
{
    if(ui->label_6->text()=="off")
    {
        int kfjb=0;
        ui->label_6->setText("on");
        emit mobalarm(kfjb);
    }
    else if(ui->label_6->text()=="on")
    {
        int kfjb=1;
        ui->label_6->setText("off");
        emit mobalarm(kfjb);
    }
}

void ModbusWig::gust_temkz()
{
    if(ui->label_3->text()=="off")
    {
        QMessageBox::information(this,"information","Turn on the air conditioner first");
    }
    else if(ui->label_3->text()=="on")
    {
        QString wendu=ui->lineEdit->text();
        emit mobtem(wendu);
    }
}

void ModbusWig::modsx()
{
    int index=1;
    emit shuaxin(index);
}

